package com.kujie.ai.loader.file;

import org.springframework.core.io.ClassPathResource;
import org.springframework.util.StreamUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class PromptTemplateLoader {

    private static final String TEMPLATE_DIR = "template/prompt/";
    private static final String TEMPLATE_PREFIX = "system-prompt-";
    private static final String TEMPLATE_SUFFIX = ".txt";

    /**
     * 根据角色加载对应的提示模板
     *
     * @param role 角色名称
     * @return 模板内容
     * @throws IOException 文件读取异常
     */
    public String loadTemplateByRole(String role) throws IOException {
        // 构造文件名
        String fileName = TEMPLATE_PREFIX + role + TEMPLATE_SUFFIX;

        ClassPathResource resource = new ClassPathResource(TEMPLATE_DIR + fileName);

        return StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8);
    }
}
